Option Explicit
Sub F_Sample053()
    'Microsoft ActiveX Data Objects 2.X Library ]wޥζ
    'Microsoft ADO Ext. 2.1 for DDL and Security ]wޥζ
    'bոƃ^ F_Sample036һs@XӪwqg ADO_TABLEDEF
    Dim myCon As New ADODB.Connection
    Dim myCat As New ADOX.Catalog
    Dim mytbl As New ADOX.Table
    Dim myClm As ADOX.Column
    Dim myIdx As New ADOX.Index
    Dim mySht As Worksheet
    Dim i     As Long
    On Error Resume Next
    Set mySht = Worksheets("ADO_TABLEDEF")     'wq
    On Error GoTo 0
    If mySht Is Nothing Then
        MsgBox "Swqsb"
        Exit Sub
    End If
    mySht.Activate
    myCon.Provider = "SQLOLEDB"                        'Ѫ
    'wnsA
    myCon.Open _
    ConnectionString:="Data Source=SERVERNAME;Initial Catalog=mysample;", _
    UserID:="sa", Password:=""
    Set myCat.ActiveConnection = myCon
    On Error Resume Next
    'RJs
    myCat.Tables.Delete Cells(2, 1).Value
    On Error GoTo 0
    'ުs@
    myIdx.Name = "PrimaryKey"
    myIdx.PrimaryKey = True
    With mytbl
        .Name = Cells(2, 1).Value
        For i = 3 To Range("A1").End(xlDown).Row
            Set myClm = New Column
            myClm.Name = Cells(i, 2).Value
            myClm.Type = GetConstNo_ADO(Cells(i, 3).Value)
            If Cells(i, 4).Value > 0 Then
                myClm.DefinedSize = Cells(i, 4).Value
                myClm.Attributes = adColNullable
            End If
            .Columns.Append myClm
            If Cells(i, 6).Value = "P" Then
                myIdx.Columns.Append Cells(i, 2).Value
            End If
        Next
    End With
    'Nwqxs
    myCat.Tables.Append mytbl
    mytbl.Indexes.Append myIdx
    myCon.Close
    Set mySht = Nothing                                '
    Set myIdx = Nothing
    Set mytbl = Nothing
    Set myCon = Nothing
    Set myCat = Nothing
End Sub
